package sjtu.ist.warehouse4ws.action;

import java.util.HashMap;
import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;

//import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.ServletActionContext;

import sjtu.ist.warehouse4ws.jcr.RepositoryMoudl;

import com.opensymphony.xwork2.ActionSupport;

public class ExportOripsAction extends ActionSupport{
private RepositoryMoudl repositoryMoudlService;
    
	
	public RepositoryMoudl getRepositoryMoudlService() {
		return repositoryMoudlService;
	}

	public void setRepositoryMoudlService(RepositoryMoudl repositoryMoudlService) {
		this.repositoryMoudlService = repositoryMoudlService;
	}
	public String exportOrips(){
		Subject currentUser = SecurityUtils.getSubject();
		String companyId=currentUser.getSession().getAttribute("companyId").toString();	

		HttpServletRequest request = ServletActionContext.getRequest();
		String xmlName = request.getParameter("nodeName");
		String xmlVersion=request.getParameter("nodeVersion");
		HashMap <String,String>fs=this.repositoryMoudlService.getAllFile(companyId, xmlName, xmlVersion,"domain");
		
//		JaxWsDynamicClientFactory dcf =
//			 JaxWsDynamicClientFactory.newInstance();
//			 org.apache.cxf.endpoint.Client client = dcf
//			 .createClient("http://202.120.40.86:5191/oripsResourcePool/ThreeStoneIntegrator?wsdl");
			 Object[] objects = null;
			 try {
			 String xml="<domain_models>";
			 Iterator it = fs.keySet().iterator();
				while (it.hasNext()) {

					String key = (String) it.next();

					xml+=fs.get(key);
				}
			 xml+="</domain_models>";
			 System.out.println(xml);
	//		 objects = client.invoke("domainModelToResourcePoolFiles", xml);
			 } catch (Exception e) {
			 // TODO Auto-generated catch block
			 e.printStackTrace();
			 }
			 //输出调用结果
			//System.out.println(objects[0].toString());
		return SUCCESS;
	}

}
